package org.fast.develop.logicflow.runtime;

import org.fast.develop.logicflow.core.meta.shape.LogicFlowDefinition;
import org.fast.develop.logicflow.core.meta.LogicFlowDefinitionFactory;
import org.fast.develop.logicflow.runtime.instance.LogicFlowInstance;

import java.util.UUID;

/**
 * @author 莫寅
 * @createTime 2022-11-24 12:07
 * @desc：
 */
public class LogicFlowInstanceFactory {

    private LogicFlowDefinitionFactory logicFlowFactory;

    public LogicFlowInstanceFactory(LogicFlowDefinitionFactory logicFlowFactory) {
        this.logicFlowFactory = logicFlowFactory;
    }

    public LogicFlowInstance create(LogicFlowDefinition logicFlowDefinition){
        LogicFlowInstanceParser logicFlowNodeBuilder = new LogicFlowInstanceParser(logicFlowDefinition);
        LogicFlowInstance logicFlowInstance = new LogicFlowInstance();
        logicFlowInstance.setLogicflowInstanceId(UUID.randomUUID().toString());
        logicFlowInstance.setLogicFlowNode(logicFlowNodeBuilder.parse());
        return logicFlowInstance;
    }

    public LogicFlowInstance create(String jsonSchema){

        LogicFlowDefinition logicFlowDefinition = logicFlowFactory.create(jsonSchema);

        LogicFlowInstanceParser logicFlowNodeBuilder = new LogicFlowInstanceParser(logicFlowDefinition);

        LogicFlowInstance logicFlowInstance = new LogicFlowInstance();

        logicFlowInstance.setLogicflowInstanceId(UUID.randomUUID().toString());
        logicFlowInstance.setLogicFlowNode(logicFlowNodeBuilder.parse());
        return logicFlowInstance;
    }



}
